//
//  CaoZuoDanQueryListCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/25.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CaoZuoDanQueryListCell.h"

@interface CaoZuoDanQueryListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UIButton *fuZhiBtn;
//@property (nonatomic, strong) UIButton *operationBtn;
@property (nonatomic, strong) UILabel *fromAddLab;
@property (nonatomic, strong) UIImageView *statusImgView;
@property (nonatomic, strong) UILabel *statusLab;
@property (nonatomic, strong) UILabel *toAddLab;
@property (nonatomic, strong) UILabel *companyTitleLab;
@property (nonatomic, strong) UILabel *companyLab;
@property (nonatomic, strong) UILabel *timeTitleLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UIImageView *sureImgView;
@property (nonatomic, strong) UILabel *sureLab;

@end

@implementation CaoZuoDanQueryListCell

+ (instancetype)CaoZuoDanQueryListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"CaoZuoDanQueryListCell";
    CaoZuoDanQueryListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CaoZuoDanQueryListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        self.noTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.noLab];
        
        self.fuZhiBtn = [UIButton new];
        [self.bgView addSubview:self.fuZhiBtn];
        
        self.fromAddLab = [UILabel new];
        self.fromAddLab.textColor = HexColor(0x2B2C44);
        self.fromAddLab.font = BoldFontOfSize(20);
        self.fromAddLab.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.fromAddLab];
        
        self.statusImgView = [UIImageView new];
        [self.bgView addSubview:self.statusImgView];
        
        self.statusLab = [UILabel new];
        self.statusLab.textColor = HexColor(0x2B2C44);
        self.statusLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.statusLab];
        
        self.toAddLab = [UILabel new];
        self.toAddLab.textColor = HexColor(0x2B2C44);
        self.toAddLab.font = BoldFontOfSize(20);
        self.toAddLab.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.toAddLab];
        
        self.companyTitleLab = [UILabel new];
        self.companyTitleLab.textColor = HexColor(0x9C9DB3);
        self.companyTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.companyTitleLab];
        
        self.companyLab = [UILabel new];
        self.companyLab.textColor = HexColor(0x2B2C44);
        self.companyLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.companyLab];
        
        self.timeTitleLab = [UILabel new];
        self.timeTitleLab.textColor = HexColor(0x9C9DB3);
        self.timeTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeTitleLab];
        
        self.timeLab = [UILabel new];
        self.timeLab.textColor = HexColor(0x2B2C44);
        self.timeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.timeLab];
        
        self.sureImgView = [UIImageView new];
        self.sureImgView.image = [UIImage imageNamed:@"icon_caoZuoDan_sure_sel"];
        [self.bgView addSubview:self.sureImgView];
        
        self.sureLab = [UILabel new];
        self.sureLab.textColor = HexColor(0x9C9DB3);
        self.sureLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.sureLab];
    }
    return self;
}

-(void)setModel:(CaoZuoDanMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    self.noTitleLab.text = @"操作单号：";
    self.noTitleLab.nim_left = 10;
    self.noTitleLab.nim_top = 15;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.operating_num;
    self.noLab.nim_left = self.noTitleLab.nim_right;
    [self.noLab sizeToFit];
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.fuZhiBtn.nim_left = self.noLab.nim_right + 6;
    self.fuZhiBtn.nim_width = 18;
    self.fuZhiBtn.nim_height = 18;
    self.fuZhiBtn.nim_centerY = self.noLab.nim_centerY;
    [self.fuZhiBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
    
    self.statusImgView.nim_width = 81;
    self.statusImgView.nim_height = 10;
    self.statusImgView.nim_left = (self.bgView.nim_width - 81) * 0.5;
    self.statusImgView.nim_top = self.fuZhiBtn.nim_bottom + 33;
    if (self.model.status == CaoZuoDanStatusNew) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_new"]];
        self.statusLab.text = @"新建";
    }else if (self.model.status == CaoZuoDanStatusSure) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_sure"]];
        self.statusLab.text = @"确认";
    }else if (self.model.status == CaoZuoDanStatusBoHui) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_boHui"]];
        self.statusLab.text = @"驳回";
    }else if (self.model.status == CaoZuoDanStatusJiaoHuoChuFa) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_JiaoHuo"]];
        self.statusLab.text = @"交货出发";
    }else if (self.model.status == CaoZuoDanStatusJiaoHuoDaoDa) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_JiaoHuo"]];
        self.statusLab.text = @"交货到达";
    }else if (self.model.status == CaoZuoDanStatusGanXianQianShou) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_JiaoHuo"]];
        self.statusLab.text = @"干线签收";
    }else if (self.model.status == CaoZuoDanStatusGanXianChuFa) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_GanXian"]];
        self.statusLab.text = @"干线出发";
    }else if (self.model.status == CaoZuoDanStatusGanXianTuZhong) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_GanXian"]];
        self.statusLab.text = @"干线途中";
    }else if (self.model.status == CaoZuoDanStatusGanXianDaoDa) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_GanXian"]];
        self.statusLab.text = @"干线到达";
    }else if (self.model.status == CaoZuoDanStatusPaiSongQianShou) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_GanXian"]];
        self.statusLab.text = @"派送签收";
    }else if (self.model.status == CaoZuoDanStatusYunDanQianShou) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_YunDan"]];
        self.statusLab.text = @"运单签收";
    }else if (self.model.status == CaoZuoDanStatusHuiDanFanHui) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_HuiDan"]];
        self.statusLab.text = @"回单返回";
    }else if (self.model.status == CaoZuoDanStatusFinish) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_finish"]];
        self.statusLab.text = @"完成";
    }else if (self.model.status == CaoZuoDanStatusZuoFei) {
        [self.statusImgView setImage:[UIImage imageNamed:@"caoZuoDan_zuoFei"]];
        self.statusLab.text = @"作废";
    }
    
    
    [self.statusLab sizeToFit];
    self.statusLab.nim_centerX = self.statusImgView.nim_centerX;
    self.statusLab.nim_top = self.statusImgView.nim_bottom + 10;
    
    self.fromAddLab.nim_left = 10;
    self.fromAddLab.text = self.model.origin;
    [self.fromAddLab sizeToFit];
    self.fromAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.fromAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.toAddLab.nim_left = 10+self.statusImgView.nim_right;
    self.toAddLab.text = self.model.destination;
    [self.toAddLab sizeToFit];
    self.toAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.toAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.companyTitleLab.text = @"托运方：";
    [self.companyTitleLab sizeToFit];
    self.companyTitleLab.nim_left = 10;
    self.companyTitleLab.nim_top = self.statusImgView.nim_bottom + 50;
    
    self.companyLab.text = self.model.tlogistics_name;
    [self.companyLab sizeToFit];
    self.companyLab.nim_left = self.companyTitleLab.nim_right;
    self.companyLab.nim_centerY = self.companyTitleLab.nim_centerY;
    self.companyLab.nim_width = self.bgView.nim_width - 10 - self.companyTitleLab.nim_right;
    
    self.timeTitleLab.text = @"发运时间：";
    [self.timeTitleLab sizeToFit];
    self.timeTitleLab.nim_left = 10;
    self.timeTitleLab.nim_top = self.companyTitleLab.nim_bottom + 5;
    
    self.timeLab.text = self.model.trunkline_start_time;
    [self.timeLab sizeToFit];
    self.timeLab.nim_left = self.timeTitleLab.nim_right;
    self.timeLab.nim_centerY = self.timeTitleLab.nim_centerY;
    self.timeLab.nim_width = self.bgView.nim_width - 10 - self.timeTitleLab.nim_right;
    
    if (self.model.supplier_status == CaoZuoDanOperationStatusSure) {
        self.sureLab.text = @"已确认，等待其他供应商受理";
        [self.sureLab sizeToFit];
        self.sureLab.nim_left = self.bgView.nim_width - 15 - self.sureLab.nim_width;
        self.sureLab.nim_top = self.timeTitleLab.nim_bottom + 15;
        
        self.sureImgView.nim_left = self.sureLab.nim_left - 5 - 12;
        self.sureImgView.nim_width = 12;
        self.sureImgView.nim_height = 12;
        self.sureImgView.nim_centerY = self.sureLab.nim_centerY;
        
        self.bgView.nim_height = self.sureLab.nim_bottom + 10;
    }else {
        self.sureImgView.frame = CGRectZero;
        self.sureLab.frame = CGRectZero;
        self.bgView.nim_height = self.timeTitleLab.nim_bottom + 15;
    }
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
